package com.base.core;

/**
 * 响应结果生成工具
 */
public class ApiResponseBuilder {

    private static final String DEFAULT_SUCCESS_MESSAGE = "操作成功";

    private static final String DEFAULT_FAIL_MESSAGE = "操作失败";

    public static ApiResponse success() {
        return new ApiResponse()
                .setCode(ResponseCode.SUCCESS)
                .setMessage(DEFAULT_SUCCESS_MESSAGE);
    }

    public static ApiResponse success(Object data) {
        return new ApiResponse()
                .setCode(ResponseCode.SUCCESS)
                .setMessage(DEFAULT_SUCCESS_MESSAGE)
                .setData(data);
    }

    public static ApiResponse fail(String message) {
        return new ApiResponse()
                .setCode(ResponseCode.FAIL)
                .setMessage(message);
    }

    public static ApiResponse fail() {
        return new ApiResponse()
                .setCode(ResponseCode.FAIL)
                .setMessage(DEFAULT_FAIL_MESSAGE);
    }

    public static ApiResponse unAuthorized(String message) {
        return new ApiResponse().setCode(ResponseCode.UNAUTHORIZED).setMessage(message);
    }

    public static ApiResponse notFound(String message) {
        return new ApiResponse().setCode(ResponseCode.NOT_FOUND).setMessage(message);
    }

    public static ApiResponse serverError(String message) {
        return new ApiResponse().setCode(ResponseCode.INTERNAL_SERVER_ERROR).setMessage(message);
    }
}
